﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AccessLogCleaner.Logs;

namespace AccessLogCleaner
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        //collection to bind the listbox to.
        

        public MainWindow()
        {
            InitializeComponent();
        }

        private void OpenClicked(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Multiselect = true;
            dlg.InitialDirectory = "%USERPROFILE%\\My Documents";
            dlg.Filter = "Access Logs|*.log|Text Files|*.txt|All Files|*.*";
            dlg.FileOk += new System.ComponentModel.CancelEventHandler(OpenFileRequested);
            dlg.ShowDialog(this);
        }

        private void OnCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            Control ctrl = e.Source as Control;
            if (ctrl != null)
                e.CanExecute = true;
            else
                e.CanExecute = false;
        }

        private void CloseClicked(object sender, ExecutedRoutedEventArgs e)
        {
            this.Close();
        }

        public void OpenFileRequested(object sender, System.ComponentModel.CancelEventArgs e)
        {
            string[] files = null;
            if (!e.Cancel)
                files = ((Microsoft.Win32.OpenFileDialog)sender).FileNames;

            foreach (string file in files)
            {
                this.visualLogStack.Items.Add(new LogControl());
                this.visualLogStack.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
            }
        }

        private void AboutClicked(object sender, RoutedEventArgs e)
        {
            
        }

        private void ProcessLogsButtonClicked(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("We should be processing some logs now");
        }
    }
}
